using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpeedFloor : MonoBehaviour
{
    public bool isDown;
    private Collider2D coll;
    private Collider2D playerColl;
    // Start is called before the first frame update
    void Start()
    {
        coll = GetComponent<Collider2D>();
    }

    // Update is called once per frame
    void Update()
    {
        if (coll.IsTouchingLayers(LayerMask.GetMask("Player")))
        {
            if (!isDown)
            {
                if (playerColl.GetComponent<PlayerCon>().parameterPlayer.speed <= 10)
                {
                    playerColl.GetComponent<PlayerCon>().parameterPlayer.speed = 10;
                    Invoke("ReSpeed", 3f);
                }
            }
            else
            {
                if (playerColl.GetComponent<PlayerCon>().parameterPlayer.speed >= 5)
                {
                    playerColl.GetComponent<PlayerCon>().parameterPlayer.speed = 5;
                    Invoke("ReSpeed", 3f);
                }
            }
        }
    }
    void ReSpeed()
    {
        playerColl.GetComponent<PlayerCon>().parameterPlayer.speed = 7;
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.layer == LayerMask.NameToLayer("Player"))
        {
            playerColl = collision;
        }
    }
}
